package cn.itsource.langxun.controller;

import cn.itsource.langxun.util.AjaxResult;
import cn.itsource.langxun.util.VelocityUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PageController {

    /**
     * 页面静态化
     * @param templatePath 模板文件路径
     * @param targetPath 目标文件路径
     * @param data 数据
     */
    @PostMapping("/page")
    public AjaxResult genStaticPage(
            @RequestParam("templatePath") String templatePath,
            @RequestParam("targetPath") String targetPath,
            @RequestBody Object data
    ){
        try {
            VelocityUtils.staticByTemplate(data, templatePath, targetPath);
            return AjaxResult.li().setSuccess(true).setMessage("成功！");
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.li().setSuccess(false).setMessage("失败!"+e.getMessage());
        }
    }

}
